﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ZhaoxiLearningWpf.Common
{
    public class CommandBase : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public Action<object> DoExecute;

        public Func<object, bool> DoCanExecute;

        public bool CanExecute(object parameter)
        {
            return DoCanExecute?.Invoke(parameter)==true; 
        }

        public void Execute(object parameter)
        {
            DoExecute?.Invoke(parameter);
        }

        public void RasieCanExecuteChanged()
        {
            EventHandler handler = this.CanExecuteChanged;
            if (handler != null) {
                handler(this, EventArgs.Empty);
            }
        }
    }
}
